﻿using System;
using System.Collections.Generic;

namespace WeiTap.Web.BodyParsers
{
    /// <summary>
    /// 表示一个正文解析器
    /// </summary>
    public interface IHttpBodyParser:ICustomFormatter
    {
        /// <summary>
        /// 匹配解析器,返回 true 表示匹配成功
        /// </summary>
        /// <param name="type"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        bool IsMatch(string type, string format);
        /// <summary>
        /// 将正文格式化为字节流
        /// </summary>
        /// <param name="formate"></param>
        /// <param name="body"></param>
        /// <param name="formatProvider">它提供有关当前实例的格式信息</param>
        /// <returns></returns>
        byte[] Serialize(string formate, IEnumerable<KeyValuePair<string, object>> body, IFormatProvider formatProvider);
        /// <summary>
        /// 将字节流转换为键值对枚举
        /// </summary>
        /// <param name="bytes"></param>
        /// <param name="formatProvider">它提供有关当前实例的格式信息</param>
        /// <returns></returns>
        IEnumerable<KeyValuePair<string, object>> Deserialize(byte[] bytes, IFormatProvider formatProvider);
        /// <summary>
        ///  将字节流转换为指定对象
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="bytes"></param>
        /// <param name="formatProvider">它提供有关当前实例的格式信息</param>
        /// <returns></returns>
        T Deserialize<T>(byte[] bytes, IFormatProvider formatProvider);
    }
}